package
{
	
	
	import mx.collections.ArrayCollection;
	import flash.utils.flash_proxy;
	
	use namespace flash_proxy;
	

	public class Struct extends ArrayCollection
	{
		public function Struct(source:Array=null)
		{
			super(source);
		}
		
		
		private var _keyIndex:Object = new Object();
		

		public function get keyIndex():Object
    	{
        	return _keyIndex;
    	}

   
   		public function set keyIndex(value:Object):void
    	{
        	_keyIndex = value;
    	}
		
		
		[Bindable("hasKeyChanged")]
		public function hasKey(key:String):Boolean
		{
			if(this.keyIndex[key] == null)
				return false;		
			return true;
		}
		
		
		
		
		[Bindable("collectionChange")]
		public function addByKey(key:Object,value:Object):void 
		{
			var index:* = keyIndex[key];
			if (index == null) 
			{
				index = this.length;
				this.addItem(value);
				keyIndex[key] = index;
				this.setItemAt(value,index as int);
			} 
			else 
			{
				this.setItemAt(value,index as int);
			}
		}			
		
		[Bindable("collectionChange")]
		public function getByKey(key:Object):Object 
		{
			var index:* = keyIndex[key];

			if (index == undefined) 
				return null

			return super.getItemAt( index as int);
		}
		
		
		
		override flash_proxy function getProperty(name:*):*
    	{	
    		
    		if(this.hasOwnProperty(name))
    		{
    			return super.getProperty(name);
    		}
    		
    		return getByKey(name);
    	}
    	
		override flash_proxy function setProperty(name:*, value:*):void
    	{
    		if(this.hasOwnProperty(name))
    		{
    			super.setProperty(name,value);
    		}
    		else
    		{
    			addByKey(name,value);
    		}	
    	} 
    	
    	
    	
		
	}
}